import numpy as np
import pandas as pd

def entropy_weight(df: pd.DataFrame, columns: list) -> pd.Series:
    """
    计算指标的熵权法权重
    :param df: 包含指标数据的 DataFrame
    :param columns: 指标列名称列表
    :return: 包含权重的 Series
    """
    data = df[columns].copy()
    # 最小-最大归一化
    data = (data - data.min()) / (data.max() - data.min())
    eps = 1e-12  # 防止log(0)
    p = data.div(data.sum(axis=0) + eps)
    e = - (p * np.log(p + eps)).sum(axis=0) / np.log(len(df))
    d = 1 - e
    w = d / d.sum()
    return pd.Series(w, index=columns, name="Entropy_Weight")
